import 'package:flutter/material.dart';
import 'package:flutter_app/tabs/userpage/journals/journal1.dart';

List MyJournalList = [
  {
    "name": '新增',
    "coverStream": 'images/UserPage/New_Journal.png',
    "pages": 1,
    "imageStream": ['images/UserPage/journal1_1.jpg'],
    "imageTitle": ['样例'],
  },
  {
    "name": 'journal1',
    "coverStream": 'images/UserPage/journal1_0.png',
    "pages": 2,
    "imageStream": [
      'images/UserPage/journal1_1.jpg',
      'images/UserPage/journal1_2.jpg'
    ],
    "imageTitle": ['抵达', '你好'],
  },
  {
    "name": 'journal2',
    "coverStream": 'images/UserPage/journal2_0.jpg',
    "pages": 1,
    "imageStream": ['images/UserPage/journal2_1.jpg'],
    "imageTitle": ['春天'],
  }
];

class MyJournal extends StatefulWidget {
  MyJournal({Key key}) : super(key: key);

  @override
  _MyJournalState createState() => _MyJournalState();
}

class _MyJournalState extends State<MyJournal> {
  Widget _getJournal(context, index) {
    return Container(
      child: Text("asdf"),
      color: Colors.yellow,
    );
  }

  @override
  Widget build(BuildContext context) {
    return Padding(
        child: Container(
          constraints: BoxConstraints.expand(),
          decoration: BoxDecoration(
            color: Color.fromRGBO(250, 245, 223, 1),
            borderRadius: BorderRadius.all(Radius.circular(20)),
          ),
          child: Stack(
            alignment: Alignment.topCenter,
            children: <Widget>[
              Container(
                height: 60,
                alignment: Alignment.center,
                child: Text("My Journal"),
                decoration: BoxDecoration(
                  color: Color.fromRGBO(239, 232, 203, 1),
                  borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
                ),
              ),
              Positioned(
                top: 70,
                left: 10,
                right: 10,
                bottom: 10,
                child: show_Journal(),
              )
            ],
          ),
        ),
        padding: EdgeInsets.fromLTRB(20, 10, 20, 10));
  }
}

class show_Journal extends StatelessWidget {
  Widget _getJournal(context, index) {
    return Container(
        child: RaisedButton(
      onPressed: () {
        Navigator.push(
            context,
            MaterialPageRoute(
                builder: (context) => journal(MyJournalList[index])));
      },
      autofocus: true,
      padding: EdgeInsets.all(0),
      child: Image.asset(
        MyJournalList[index]['coverStream'],
        fit: BoxFit.fill,
      ),
    ));
  }

  @override
  Widget build(BuildContext context) {
    return GridView.builder(
      gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
          crossAxisCount: 3,
          crossAxisSpacing: 10,
          mainAxisSpacing: 10,
          childAspectRatio: 0.7),
      itemCount: MyJournalList.length,
      itemBuilder: this._getJournal,
    );
  }
}
